package com.briup.bms.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.briup.bms.common.utils.Result;
import com.briup.bms.common.utils.ResultCode;
import com.fasterxml.jackson.databind.ObjectMapper;

@Component //表明当前对象是受Spring容器管理的对象，需要Spring容器创建及维护。@service @Repository,@Controller,@RestController
public class FirstInterceptor implements HandlerInterceptor{
	
	public FirstInterceptor() {
		System.out.println("FirstInterceptor 创建。。。。。。。。。");
	}
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 
			Object handler)
			throws Exception {
		System.out.println("FirstInterceptor preHandler............"+request.getRequestURI());
		System.out.println(" 拦截到的处理器是 ： "+handler.getClass()+"....."+handler);
		System.out.println("===========================");
//		response.setContentType("text/plain;charset=UTF-8");
//		response.getWriter().println("First interceptor response......");
//		response.getWriter().flush();
		return true;
	}
	
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, 
			Object handler, ModelAndView modelAndView) throws Exception {
		System.out.println("FirstInterceptor ..... post handler.....................");
		System.out.println("拦截到的处理器是:..."+handler.getClass()+"..... "+handler);
		System.out.println("modelAndView: "+modelAndView);
		System.out.println("----------------------------------------------------");
	}
	
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, 
			Object handler, Exception ex)
			throws Exception {
		System.out.println("FirstInterceptor.......afterCompletion..........");
		System.out.println("-----------------------------"+handler+"......."+ex);
	}
}
